package it.stasbranger.myproject.web.rest;

import it.stasbranger.myproject.dao.SuppliersDAO;
import it.stasbranger.myproject.dao.SuppliersHasRequestsDAO;

import it.stasbranger.myproject.domain.Suppliers;
import it.stasbranger.myproject.domain.SuppliersHasRequests;

import it.stasbranger.myproject.service.SuppliersService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for Suppliers entities
 * 
 */

@Controller("SuppliersRestController")
public class SuppliersRestController {

	/**
	 * DAO injected by Spring that manages Suppliers entities
	 * 
	 */
	@Autowired
	private SuppliersDAO suppliersDAO;

	/**
	 * DAO injected by Spring that manages SuppliersHasRequests entities
	 * 
	 */
	@Autowired
	private SuppliersHasRequestsDAO suppliersHasRequestsDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for Suppliers entities
	 * 
	 */
	@Autowired
	private SuppliersService suppliersService;

	/**
	 * Create a new Suppliers entity
	 * 
	 */
	@RequestMapping(value = "/Suppliers", method = RequestMethod.POST)
	@ResponseBody
	public Suppliers newSuppliers(@RequestBody Suppliers suppliers) {
		suppliersService.saveSuppliers(suppliers);
		return suppliersDAO.findSuppliersByPrimaryKey(suppliers.getIdsuppliers());
	}

	/**
	 * Delete an existing Suppliers entity
	 * 
	 */
	@RequestMapping(value = "/Suppliers/{suppliers_idsuppliers}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteSuppliers(@PathVariable Integer suppliers_idsuppliers) {
		Suppliers suppliers = suppliersDAO.findSuppliersByPrimaryKey(suppliers_idsuppliers);
		suppliersService.deleteSuppliers(suppliers);
	}

	/**
	 * Show all Suppliers entities
	 * 
	 */
	@RequestMapping(value = "/Suppliers", method = RequestMethod.GET)
	@ResponseBody
	public List<Suppliers> listSupplierss() {
		return new java.util.ArrayList<Suppliers>(suppliersService.loadSupplierss());
	}

	/**
	 * Save an existing SuppliersHasRequests entity
	 * 
	 */
	@RequestMapping(value = "/Suppliers/{suppliers_idsuppliers}/suppliersHasRequestses", method = RequestMethod.PUT)
	@ResponseBody
	public SuppliersHasRequests saveSuppliersSuppliersHasRequestses(@PathVariable Integer suppliers_idsuppliers, @RequestBody SuppliersHasRequests suppliershasrequestses) {
		suppliersService.saveSuppliersSuppliersHasRequestses(suppliers_idsuppliers, suppliershasrequestses);
		return suppliersHasRequestsDAO.findSuppliersHasRequestsByPrimaryKey(suppliershasrequestses.getSuppliersIdsuppliers(), suppliershasrequestses.getRequestsIdrequests());
	}

	/**
	 * Select an existing Suppliers entity
	 * 
	 */
	@RequestMapping(value = "/Suppliers/{suppliers_idsuppliers}", method = RequestMethod.GET)
	@ResponseBody
	public Suppliers loadSuppliers(@PathVariable Integer suppliers_idsuppliers) {
		return suppliersDAO.findSuppliersByPrimaryKey(suppliers_idsuppliers);
	}

	/**
	 * Show all SuppliersHasRequests entities by Suppliers
	 * 
	 */
	@RequestMapping(value = "/Suppliers/{suppliers_idsuppliers}/suppliersHasRequestses", method = RequestMethod.GET)
	@ResponseBody
	public List<SuppliersHasRequests> getSuppliersSuppliersHasRequestses(@PathVariable Integer suppliers_idsuppliers) {
		return new java.util.ArrayList<SuppliersHasRequests>(suppliersDAO.findSuppliersByPrimaryKey(suppliers_idsuppliers).getSuppliersHasRequestses());
	}

	/**
	 * Save an existing Suppliers entity
	 * 
	 */
	@RequestMapping(value = "/Suppliers", method = RequestMethod.PUT)
	@ResponseBody
	public Suppliers saveSuppliers(@RequestBody Suppliers suppliers) {
		suppliersService.saveSuppliers(suppliers);
		return suppliersDAO.findSuppliersByPrimaryKey(suppliers.getIdsuppliers());
	}

	/**
	 * Create a new SuppliersHasRequests entity
	 * 
	 */
	@RequestMapping(value = "/Suppliers/{suppliers_idsuppliers}/suppliersHasRequestses", method = RequestMethod.POST)
	@ResponseBody
	public SuppliersHasRequests newSuppliersSuppliersHasRequestses(@PathVariable Integer suppliers_idsuppliers, @RequestBody SuppliersHasRequests suppliershasrequests) {
		suppliersService.saveSuppliersSuppliersHasRequestses(suppliers_idsuppliers, suppliershasrequests);
		return suppliersHasRequestsDAO.findSuppliersHasRequestsByPrimaryKey(suppliershasrequests.getSuppliersIdsuppliers(), suppliershasrequests.getRequestsIdrequests());
	}

	/**
	 * Register custom, context-specific property editors
	 * 
	 */
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	 * View an existing SuppliersHasRequests entity
	 * 
	 */
	@RequestMapping(value = "/Suppliers/{suppliers_idsuppliers}/suppliersHasRequestses/{suppliershasrequests_suppliersIdsuppliers}/{suppliershasrequests_requestsIdrequests}", method = RequestMethod.GET)
	@ResponseBody
	public SuppliersHasRequests loadSuppliersSuppliersHasRequestses(@PathVariable Integer suppliers_idsuppliers, @PathVariable Integer related_suppliershasrequestses_suppliersIdsuppliers, @PathVariable Integer related_suppliershasrequestses_requestsIdrequests) {
		SuppliersHasRequests suppliershasrequests = suppliersHasRequestsDAO.findSuppliersHasRequestsByPrimaryKey(related_suppliershasrequestses_suppliersIdsuppliers, related_suppliershasrequestses_requestsIdrequests, -1, -1);

		return suppliershasrequests;
	}

	/**
	 * Delete an existing SuppliersHasRequests entity
	 * 
	 */
	@RequestMapping(value = "/Suppliers/{suppliers_idsuppliers}/suppliersHasRequestses/{suppliershasrequests_suppliersIdsuppliers}/{suppliershasrequests_requestsIdrequests}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteSuppliersSuppliersHasRequestses(@PathVariable Integer suppliers_idsuppliers, @PathVariable Integer related_suppliershasrequestses_suppliersIdsuppliers, @PathVariable Integer related_suppliershasrequestses_requestsIdrequests) {
		suppliersService.deleteSuppliersSuppliersHasRequestses(suppliers_idsuppliers, related_suppliershasrequestses_suppliersIdsuppliers, related_suppliershasrequestses_requestsIdrequests);
	}
}